#ifndef __MODELEDITOR_MAINFRAME_H__
#define __MODELEDITOR_MAINFRAME_H__

#include "ControlPanel.h"
#include "EditorD3DCanvas.h"
#include "EditorToolBar.h"

class ModelEditorMainFrame
{
public:
	ModelEditorMainFrame();
	~ModelEditorMainFrame() { }


	void	CreateLayout();
	void	resized(int width, int height);

	void	HideLeftPanel();
	void	HideRightPanel();
	void	HideBottomPanel();
	void	ShowLeftPanel();
	void	ShowRightPanel();
	void	ShowBottomPanel();
	
	int		GetLeftPanelWidth()		{ return m_pLeftComponent->getWidth();				}
	int		GetLeftPanelHeight()	{ return m_pLeftComponent->getHeight();				}
	int		GetRightPanelWidth()	{ return m_pRightComponent->getWidth();				}
	int		GetRightPanelHeight()	{ return m_pRightComponent->getHeight();			}
	int		GetBottomPanelWidth()	{ return m_pD3DCanvas->m_ControlPanel->getWidth();	}
	int		GetBottomPanelHeight()	{ return m_pD3DCanvas->m_ControlPanel->getHeight(); }

public:
	int		m_width;
	int		m_height;
	bool	m_bShowLeft;
	bool	m_bShowRight;
	bool	m_bShowBottom;

public:
	class MainViewComponent   : public Component
	{
	public:
		MainViewComponent(ModelEditorMainFrame *pMainFrame)
		{
			m_pMainFrame = pMainFrame;
			addAndMakeVisible( &m_RenderCanvas );
			addAndMakeVisible( m_ControlPanel = new ControlPanelPage(pMainFrame) );

			horizontalLayout.setItemLayout(0, -0.5, -0.9, -0.85);	// hight of the upper window must be
																	// between 50% and 90% high, preferably 85%
			horizontalLayout.setItemLayout(1, 8, 8, 8);				// the horizontal divider drag-bar thing is always 8 pixels high
			horizontalLayout.setItemLayout(2, 60, -0.5, -0.15);		// the bottom components must be
																	// at least 60 pixels height, preferably 15% of the total width
 			horizontalDividerBar = new StretchableLayoutResizerBar(&horizontalLayout, 1, false);
			addAndMakeVisible(horizontalDividerBar);
		}
		~MainViewComponent() {}

		int getD3DCanvasWidth() { return m_RenderCanvas.getWidth(); }
		int getD3DCanvasHeight(){ return m_RenderCanvas.getHeight(); }
		
		void resized()
		{
			Component* vcomps[] = { &m_RenderCanvas, horizontalDividerBar, m_ControlPanel };
			horizontalLayout.layOutComponents(vcomps, 3, 0, 0, getWidth(), getHeight(), true, true); 
			
			int barpos = horizontalLayout.getItemCurrentPosition(1);
			if( m_pMainFrame->m_bShowBottom )
				horizontalDividerBar->setVisible(true);
			else
			{
				barpos = getHeight();
				horizontalDividerBar->setVisible(false);
			}
			m_RenderCanvas.setBounds(0, 0, getWidth(), barpos);
			m_ControlPanel->setBounds(0, barpos+8, getWidth(), getHeight()-barpos-8);
		}
		ModelEditorMainFrame*						m_pMainFrame;
		EditorD3DCanvas								m_RenderCanvas;
		ScopedPointer<ControlPanelPage>				m_ControlPanel;

		StretchableLayoutManager					horizontalLayout;
		ScopedPointer<StretchableLayoutResizerBar>	horizontalDividerBar;
	};

	ScopedPointer<ToolbarListener>				m_pToolbar;
	

	ScopedPointer<TabbedComponent>				m_pLeftComponent;
	ScopedPointer<TabbedComponent>				m_pRightComponent;
	ScopedPointer<MainViewComponent>			m_pD3DCanvas;


	StretchableLayoutManager					verticalLayout;
    ScopedPointer<StretchableLayoutResizerBar>	verticalDividerBarLeft;
	ScopedPointer<StretchableLayoutResizerBar>	verticalDividerBarRight;
};


#endif